<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WebSocket聊天室</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        body {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
        }
        .chat-container {
            background: white;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
            overflow: hidden;
        }
        .chat-header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 20px;
        }
        .chat-messages {
            height: 400px;
            overflow-y: auto;
            padding: 20px;
            background: #f8f9fa;
        }
        .message {
            margin-bottom: 15px;
            padding: 10px 15px;
            border-radius: 10px;
            max-width: 80%;
        }
        .message.own {
            background: #007bff;
            color: white;
            margin-left: auto;
        }
        .message.other {
            background: white;
            border: 1px solid #dee2e6;
        }
        .message.system {
            background: #ffc107;
            color: #212529;
            text-align: center;
            max-width: 100%;
        }
        .online-users {
            background: white;
            border-left: 1px solid #dee2e6;
        }
        .user-item {
            padding: 10px 15px;
            border-bottom: 1px solid #f8f9fa;
        }
        .user-item.online {
            background: #d4edda;
        }
        .login-form {
            background: white;
            border-radius: 15px;
            padding: 40px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
        }
        .hidden {
            display: none;
        }
    </style>
</head>
<body>
    <div class="container-fluid py-4">
        <!-- 登录表单 -->
        <div id="loginForm" class="row justify-content-center">
            <div class="col-md-6 col-lg-4">
                <div class="login-form">
                    <h2 class="text-center mb-4">
                        <i class="fas fa-comments text-primary"></i>
                        WebSocket聊天室
                    </h2>
                    <form id="loginFormElement">
                        <div class="mb-3">
                            <label for="username" class="form-label">用户名</label>
                            <input type="text" class="form-control" id="username" required>
                        </div>
                        <div class="mb-3">
                            <label for="password" class="form-label">密码</label>
                            <input type="password" class="form-control" id="password" required>
                        </div>
                        <div class="mb-3">
                            <label for="nickname" class="form-label">昵称</label>
                            <input type="text" class="form-control" id="nickname" required>
                        </div>
                        <div class="d-grid gap-2">
                            <button type="submit" class="btn btn-primary">登录</button>
                            <button type="button" class="btn btn-outline-primary" onclick="showRegisterForm()">注册</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <!-- 聊天界面 -->
        <div id="chatInterface" class="hidden">
            <div class="row">
                <div class="col-md-9">
                    <div class="chat-container">
                        <div class="chat-header">
                            <h4 class="mb-0">
                                <i class="fas fa-comments"></i>
                                公共聊天室
                                <span class="float-end">
                                    <span id="currentUser"></span>
                                    <button class="btn btn-outline-light btn-sm ms-2" onclick="logout()">
                                        <i class="fas fa-sign-out-alt"></i> 退出
                                    </button>
                                </span>
                            </h4>
                        </div>
                        <div class="chat-messages" id="messageArea">
                            <!-- 消息将在这里显示 -->
                        </div>
                        <div class="p-3 border-top">
                            <div class="input-group">
                                <input type="text" class="form-control" id="messageInput" placeholder="输入消息...">
                                <button class="btn btn-primary" type="button" onclick="sendMessage()">
                                    <i class="fas fa-paper-plane"></i> 发送
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="chat-container">
                        <div class="chat-header">
                            <h5 class="mb-0">
                                <i class="fas fa-users"></i>
                                在线用户 (<span id="onlineCount">0</span>)
                            </h5>
                        </div>
                        <div class="online-users" id="onlineUsersList">
                            <!-- 在线用户列表 -->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.5.1/sockjs.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.min.js"></script>
    <script src="js/chat.js"></script>
</body>
</html> 